#include "database/Client.hpp"
#include "TCPServer.h"
#include "IntegrityDatas.h"
#include "Protocol.h"

void CSProtocol::Profil::receiveTreat(TCPConnection &connexion, IData *udata)
{
  CSProtocol::Profil *data = static_cast<CSProtocol::Profil*>(udata);
  if (!data || !connexion.getAuthenticate())
    return;
  CSProtocol::Header header = CSProtocol::Header();
  header.spontaneous = false;
  IData *pcmd;
  std::map<std::string, Client*> &lclts = connexion.getServer()->getDB().getClients();
  lclts[connexion.getClient()->getLogin()]->setAge(data->age);
  lclts[connexion.getClient()->getLogin()]->setPseudo(data->pseudo);
  lclts[connexion.getClient()->getLogin()]->save();
  header.code = CSProtocol::Ok::code;
  CSProtocol::Ok command = CSProtocol::Ok();
  pcmd = &command;
  strcpy(command.what, "Profil updated.");
  header.dataLength = sizeof(CSProtocol::Ok);
  connexion.write(header, *pcmd);
}

void CSProtocol::Profil::sendTreat(TCPConnection &connexion)
{

}
